package com.zhaorui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhaorui.component.BusinessException;
import com.zhaorui.entity.ActivityDictionary;
import com.zhaorui.entity.ActivitySysLog;
import com.zhaorui.entity.ActivityUser;
import com.zhaorui.form.DictionaryAddFrom;
import com.zhaorui.form.DictionaryFrom;
import com.zhaorui.mapper.ActivityUserMapper;
import com.zhaorui.service.ActivityDictionaryService;
import com.zhaorui.mapper.ActivityDictionaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class ActivityDictionaryServiceImpl extends ServiceImpl<ActivityDictionaryMapper, ActivityDictionary>
        implements ActivityDictionaryService {
    @Autowired
    private ActivityDictionaryMapper activityDictionaryMapper;

    //等级下拉框查询
    @Override
    public List<DictionaryFrom> queryLevel() {
        return activityDictionaryMapper.queryLevel ();
    }

    //会员综合查询
    @Override
    public List<DictionaryAddFrom> queryAllLevel(ActivityDictionary activityDictionary) {
        List<DictionaryAddFrom> activityDictionaries = activityDictionaryMapper.queryAllLevel (activityDictionary);
        return activityDictionaries;
    }

    //会员等级新增
    @Override
    public Integer saveLevel(ActivityDictionary activityDictionary) {
        //添加时姓名不能重复
        Integer num = activityDictionaryMapper.queryLevelNo (activityDictionary);
        if (num > 0) {//抛出异常
            throw new BusinessException ("账号重复，添加失败！");
        }
//        this.baseMapper.insert (activityDictionary);
        activityDictionaryMapper.saveLevel (activityDictionary);
        return num;
    }

    //会员等级删除
    @Override
    public boolean delete(Integer id) {
        Integer num = activityDictionaryMapper.queryUsersId (id);
        if (num != 0) {
            activityDictionaryMapper.updateBydel (id);
            return true;
        }
        return false;
    }

    //活动随机类下拉框查询
    @Override
    public List<DictionaryFrom> queryTitle() {
        return activityDictionaryMapper.queryTitle();
    }

}




